<style>
	.table2{
		width: 500px;
		margin: 0 auto;
		border: 1px solid black;
	}
	table{
		margin: 0 auto;
	}
	h1{
		text-align: center;
	}
	td{
		padding-bottom: 5px;
	}
	input[type=submit],input[type=reset]{
		background: white;
	}
</style>
<div class="table2">
	<h1>编辑学生信息</h1>
	<table>
	<form action="#" method="post">
		<tr><td>学号:</td><td><input type="text" name="student_id"></td></tr>
		<tr><td>姓名:</td><td><input type="text" name="username"></td></tr>
		<tr><td>性别:</td><td><input type="radio" name="xingbie" value="man">man
				      <input type="radio" name="xingbie" value="woman">woman</td></tr>
		<tr><td>出生日期:</td><td><input type="text" name="birthday"></td></tr>
		<tr><td>班级:</td><td><input type="text" name="class"></td></tr>
		<tr><td>专业:</td><td><input type="text" name="major"></td></tr>
		<tr><td><input type="submit" value="保存信息" name="submit"></td><td><input type="reset" value="重新填写"></td></tr>
	</form>
	</table>
</div>
<?php
$servername = "192.168.56.103"; // MySQL 主机名
$username = "root"; // MySQL 用户名
$password = "123456"; // MySQL 密码
$dbname = "myDB"; // 要连接的数据库名称

// 创建连接
$link = new mysqli($servername, $username, $password, $dbname);
echo $link?'':'数据库连接失败';
mysqli_query($link,"set names utf8");
if(isset($_POST['submit'])){
    $student_id = $_POST['student_id'];
    $username = $_POST['username'];
    $xingbie = $_POST['xingbie'];
    $birthday = $_POST['birthday'];
    $class = $_POST['class'];
    $major = $_POST['major'];
    
    if(!empty($student_id)&&!empty($username)&&!empty($xingbie)&&!empty($birthday)&&!empty($class)&&!empty($major)){
        $query = "insert into students(major,class,student_id,name,sex,birthday)".
		"values('$major','$class','$student_id','$username','$xingbie','$birthday')";
        mysqli_query($link,$query) or die("执行语句失败");
		echo "<script>alert('保存成功');window.location.href='index.php'</script>";
    }else{
		echo "<script>alert('保存失败');window.location.href='index.php'</script>";
    }
}
?>

